<template>
	<view>
		<view class="swiperPanel" ref="swiperPanel" @touchstart="startMove" @touchend="endMove">
			<view class="swiperItem" v-for="(item, index) in list" :key="index" 
			:style="{transform: itemStyle[index].transform, zIndex: itemStyle[index].zIndex}">
			<!-- :class="index+1 == no ? 'children current': 'children current2'" -->
				<view class="children current" @tap="toCouponCenter">
					<image class="pic" src="../../static/image/home/home_img_new_bg.png"></image>
					<view class="couponList-view">
						<view class="money"><text>¥ </text>{{item.money}}</view>
						<view class="condition">满{{item.limit}}元可用</view>
						<view class="btn">
							<image src="../../static/image/home/home_ic_get.png"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var timer;
	export default {
		props: {
			list: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				slideNote: {
					x: 0,
					y: 0
				},
				screenWidth: 0,
				itemStyle: [],
				no: 0
			};
		},
		created() {
		
		},
		methods: {
			fun(){
				var macInfo = uni.getSystemInfoSync();
				this.screenWidth = macInfo.screenWidth;
				// 计算swiper样式	
				this.$nextTick(() =>{  
					console.log('轮播优惠券==',this.list)
					this.list.forEach((item, index) => {
						this.itemStyle.push(this.getStyle(index))
					})
					timer = setInterval(()=>{
						this.rightSlider();
						this.no++
						if(this.no == this.list.length + 1){
							this.no = 1
						}
					},4000)	
				})
				
				
			},
			rightSlider(){
				var newList = JSON.parse(JSON.stringify(this.itemStyle));
				var last = [newList.pop()]
				newList = last.concat(newList)
				this.itemStyle = newList;
			},
		
			getStyle(e) {
				let option = {};
				// if (e > this.list.length / 2) {
				// 	var right = this.list.length - e;
				// 	option.transform = 'scale(' + (1 - right / 10) + ') translate(-' + (right * 9) + '%,0px)';
				// 	option.zIndex = 9999 - right;
				// 	option.opacity = 0.5 / right;
				// 	option.backgroundImage = 'url(/static/image/home/home_img_tic.png)';
				// } else {
				// 	option.transform = 'scale(' + (1 - e / 10) + ') translate(' + (e * 9) + '%,0px)';
				// 	option.zIndex = 9999 - e;
				// 	option.opacity = 0.5 / e;
				// 	option.backgroundImage = 'url(/static/image/home/home_img_tic.png)';
				// }
				option.transform = 'scale(' + (1 - e / 10) + ') translate(' + (e * 9) + '%,0px)';
				option.zIndex = 9999 - e;
				option.opacity = 0.5 / e;
				option.backgroundImage = 'url(/static/image/home/home_img_tic.png)';
				return option
			},
			startMove(e) {
				clearInterval(timer);
				this.slideNote.x = e.changedTouches[0] ? e.changedTouches[0].pageX : 0;
				this.slideNote.y = e.changedTouches[0] ? e.changedTouches[0].pageY : 0;
			},
			endMove(e) {
				timer = setInterval(()=>{
					this.rightSlider();
				},3000)
				var newList = JSON.parse(JSON.stringify(this.itemStyle));
				if ((e.changedTouches[0].pageX - this.slideNote.x) < 0) {
					// 向左滑动
					var last = [newList.pop()]
					newList = last.concat(newList)
				} else {
					// 向右滑动
					newList.push(newList[0])
					newList.splice(0, 1)
				}
				this.itemStyle = newList
			},

			toCouponCenter: function(){
				uni.navigateTo({
					url: '/subPackages/minorPkg/pages/couponCenter/couponCenter?type=2'
				});
			}
		}
	}
</script>

<style lang="scss">
	.swiperPanel {
		height: 188rpx;
		// width: 576rpx;
		overflow: hidden;
		position: relative;
		margin-left: 20rpx;

		.swiperItem {
			height: 100%;
			width: 100%;
			position: absolute;
			top: 0;
			left: 0upx;
			transition: all .5s;
			border-radius: 16rpx;
			
			.children {
				height: 100%;
				width: 510rpx;
				margin: 2upx 160upx 2upx 0;
				position: relative;
				background-image: url(/static/image/home/home_img_tic.png);
				background-size: 100% 100%;
				padding: 32rpx 28rpx;
				border-radius: 16rpx;
				// box-shadow: 0 14rpx 34rpx 6rpx rgba(171,163,207,0.2);
				.pic {
					height: 100%;
					width: 100%;
					border-radius: 16rpx;
				}
			}
			
			.current{
				background: linear-gradient()
			}
			
			.current2{
				background: linear-gradient(180deg, #FFFFFF 0%, #FFF1E0 100%);
			}
		}

		.couponList-view{
			position: absolute;
			display: flex;
			align-items: center;
			left: 0;
			bottom: 40rpx;
    	padding-left: 56rpx;

			.money{
				font-size: 32rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #FF6E42;
				height: 44rpx;
				line-height: 44rpx;
				padding-right: 22rpx;
				border-right: 1rpx solid #F4EEE3;
				margin-right: 12rpx;
			}

			.money text{
				font-size: 24rpx;
			}

			.condition{
				font-size: 28rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #A7702E;
				width: 168rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.btn image{
				margin-top: 20rpx;
				width: 172rpx;
				height: 74rpx;		
			}
		}
	}
</style>


